
from redis import Redis


async def redis_pool() -> Redis:
    try:
        from redis import asyncio as aioredis
        import json
        info = {}
        redis = None
        with open("./routers/database/redis.json", encoding="utf-8") as fp:
            info = json.load(fp)
            # 连接redis时带上decode_responses=False 取消对返回结果的decode('utf-8')操作,弊端是结果需要解码
            redis = await aioredis.from_url(
                url=info.get("host", "redis://127.0.0.1"), port=info.get("port", 6379), password=info.get("password", ""), db=info.get("db", 0), encoding="utf-8", decode_responses=False
            )
        return redis
    except Exception as ex:
        print("Redis Error", ex)
        return None
